<!-- 优惠券 -->
{php}
	$coupon_list = api("System.Member.canReceiveCouponQuery",['uid'=>$uid]);
	$coupon_list = $coupon_list['data'];
{/php}

{notempty name="$coupon_list"}
	{if condition="$custom_template_v.control_data.coupons.style==1"}
	<div class="coupon-all">
		{volist name="coupon_list" id="vo" }
		{if condition="$vo['money'] gt 0 && $vo['money'] elt 10"}
			<div class="coupon" style="background: #FFA72A;" onclick="couponReceive(this,{$vo.coupon_type_id})" data-max-fetch="{$vo.max_fetch}" data-received-num="{if !empty($uid)}{$vo.received_num}{else/}0{/if}">
		{elseif condition="$vo['money'] gt 10 && $vo['money'] elt 100"}
			<div class="coupon" style="background: #FF4D5B;" onclick="couponReceive(this,{$vo.coupon_type_id})" data-max-fetch="{$vo.max_fetch}" data-received-num="{if !empty($uid)}{$vo.received_num}{else/}0{/if}">
		{elseif condition="$vo['money'] gt 100"}
			<div class="coupon" style="background: #34D71E;" onclick="couponReceive(this,{$vo.coupon_type_id})" data-max-fetch="{$vo.max_fetch}" data-received-num="{if !empty($uid)}{$vo.received_num}{else/}0{/if}">
		{/if}
			<img src="__STATIC__/wapCustomTemplate/images/index_coupon.png" class="background_img">
			<p><span>￥</span>{$vo.money}</p>
			<img src="__STATIC__/wapCustomTemplate/images/already_received.png" class="already_received">
		</div>
		{/volist}
	</div>
	{elseif condition="$custom_template_v.control_data.coupons.style==2"}
	<div class="coupon-all2">
		{volist name="coupon_list" id="vo"}
		<div class="coupons-style2" onclick="couponReceive(this,{$vo.coupon_type_id})" data-max-fetch="{$vo.max_fetch}" data-received-num="{if !empty($uid)}{$vo.received_num}{else/}0{/if}">
			<span class="money-number">￥{$vo.money}</span>
			<p class="explanation">满{$vo.at_least}可用</p>
			<span class="get">领取</span>
		</div>
		{/volist}
	</div>
	{/if}

	<script type="text/javascript">
		var is_have = true;

		function couponReceive(event, coupon_type_id) {
			var info = new Array();
			info['maxFetch'] = $(event).attr("data-max-fetch");
			info['receivedNum'] = $(event).attr("data-received-num");
			
			is_have = false;
			if (is_have) return;
			api("System.Member.getCoupon", {'coupon_type_id': coupon_type_id, "scenario_type": 2}, function (res) {
				if (res.code >= 0) {
					toast('领取成功');
					is_have = true;
					var received_num = parseInt(info['receivedNum']) + 1; // 该用户已领取数
					$(event).attr("data-received-num", received_num);
					
					if (info['maxFetch'] > 0 && received_num >= info['maxFetch']) {
						$(event).find(".get").text("已领取");
						$(event).addClass("received");
					}
				} else if (res.code == -9999) {
					toast(res.message, __URL(APPMAIN + "/login/index"));
				} else {
					toast(res.message);
					is_have = true;
				}
			});
		}
	</script>
{/notempty}